#include<stdio.h>
#include <string.h>
#include <unistd.h>
#include "../busMq.h"

#define BUSID 0x789

#define TARGET_ADDR1 0x02
#define TARGET_ADDR2 0x03
#define TARGET_ADDR3 0x04


void recive_call(BUSMQ_MSG_t* msg,int addr)
{
    printf("addr:%d,recive:%d ,%s\n",addr,msg->datalen,msg->data);
    return ;
}


int main()
{
    BUSMQ_Control_t ctrol = {0};
    BUSMQ_MSG_t  sendmq= {0};
    BUSMQ_CREATE(0x789,&ctrol,(BUSMQ_RECIVE_CAMMBACK) recive_call,0x01,1);

    sleep(1);
    strcpy(sendmq.data,"this is a test camfrom 0x01");
    sendmq.datalen = strlen(sendmq.data);
    printf("\n发送100次数据\n");
    int count  = 100;
    while(count--)
    {
       
        BUSMQ_MSG_send(&ctrol,&sendmq,TARGET_ADDR1);
        BUSMQ_MSG_send(&ctrol,&sendmq,TARGET_ADDR2);
        BUSMQ_MSG_send(&ctrol,&sendmq,TARGET_ADDR3);
        sleep(1);

    }
    
     printf("\n销毁总线\n");
    BUSMQ_DESTROY_BUS(&ctrol);

}
